package com.lh.pospi.x_store.net;

import com.azhon.appupdate.utils.LogUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
//import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import com.lany.sp.SPHelper;
import com.lh.pospi.x_store.BuildConfig;
import com.lh.pospi.x_store.api.Api;
import com.lh.pospi.x_store.app.MyApp;
import com.lh.pospi.x_store.modle.BaseT;
import com.lh.pospi.x_store.modle.GoodsBean;
import com.lh.pospi.x_store.modle.RequestGoods;
import com.lh.pospi.x_store.utils.Constant;
//import com.tsy.sdk.myokhttp.response.RawResponseHandler;
import com.parkingwang.okhttp3.LogInterceptor.LogInterceptor;
import com.vondear.rxtool.RxLogTool;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

/**
 * 网络请求封装
 */
public class NetHelper{
    public interface ResponseResult{
        void success(String result);
        void failed(String msg);
    }

    public static void doPost(String url, final Map<String,String> map , final ResponseResult result) {
//        String l = "http://" + SPHelper.getInstance().getString(Constant.DB_IP) + url;
//        MyApp.getInstance().getMyOkHttp().post()
//                .url(l)
//                .params(map)
//                .enqueue(new RawResponseHandler() {
//                    @Override
//                    public void onSuccess(int statusCode, String response) {
////                        RxLogTool.e("请求数据："+map.toString()+"----->"+response);
////                        try {
////                            JSONObject object = new JSONObject(response);
////                            if (object.getString())
////                        } catch (JSONException e) {
////                            e.printStackTrace();
////                        }
//                        result.success(response);
//
//                    }
//
//                    @Override
//                    public void onFailure(int statusCode, String error_msg) {
//                        result.failed(error_msg);
//                    }
//                });
    }
    public static Api request() {
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(new HttpLoggingInterceptor()).build();

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://"+SPHelper.getInstance().getString(Constant.DB_IP))
                .client(okHttpClient)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//增加rxjava
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        return retrofit.create(Api.class);
    }

}
